home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Mac OS SDK / Dev.CD Jan 98 SDK2.toast / Development Kits (Disc 2) / ScriptX / Code Samples / tapemesr / source / maketape.sx next >
Encoding:
Text File  |  1996-05-21  |  8.5 KB  |  210 lines  |  [TEXT/ttxt]

  1. --<<<-
  2. -- Filename: 
  3. --     maketape.sx
  4. --
  5. -- Other Files Required:
  6. --     interfac.sx or interfac.sxl - defines accessory interface module
  7. --     tape.sx or tape.sxl         - defines tape measure classes
  8. --     mediaimp.sx or mediaimp.sxl - defines media importer classes
  9. --
  10. -- Purpose:  
  11. --    Builds an AccessoryContainer for the tape measure tool.
  12. --
  13. -- Specialized Classes:  
  14. --     None
  15. --
  16. -- Instructions to User: 
  17. --     Run this script to build the tape measure AccessoryContainer.
  18. --     (Be aware that in ScriptX V1.5, you may not be able to load an 
  19. --      AccessoryContainer into the KMP via simple drag-and-drop because
  20. --      the "Open" action of the KMP is defined only for TitleContainers.
  21. --      Use command-Y from a running title to bring up the Open Accessory
  22. --      menu.)
  23. --
  24. -- Author:
  25. --     Steve Mayer, Ray Davis
  26. --     Robert Lockstone : 12-15-95 : Convert to 1.5 and modularize
  27.  
  28. --*=============================================================================*
  29. --* Get the necessary tape module.  Use fileIn in case this whole thing is
  30. --* getting recompiled with a different version of ScriptX.
  31. --*=============================================================================*
  32. fileIn theScriptDir name:"tape.sx"
  33.  
  34. --*=============================================================================*
  35. --* Get the library which defines the Tape Measure classes.
  36. --* This will not open the library if the above fileIn worked.
  37. --*=============================================================================*
  38. if ((getModule @TapeInterface) = false) do 
  39.    (
  40.    open LibraryContainer dir:(parentDir theScriptDir) \
  41.                          path:"tape.sxl"              \
  42.                          mode:@readable
  43.    )
  44.  
  45. --*=============================================================================*
  46. --* Define the interface module to the Tape Measure Implementation
  47. --*=============================================================================*
  48. module TapeMeasureInterface
  49.    exports TapeMeasureAccessory
  50. end
  51.  
  52. --*=============================================================================*
  53. --* Define the Tape Measure Implementation module.
  54. --*=============================================================================*
  55. module TapeMeasureImplementation
  56.    uses ScriptX
  57.    uses TapeInterface with exports everything end
  58.    uses TapeMeasureInterface with exports everything end
  59. end
  60.  
  61. in module TapeMeasureImplementation
  62.  
  63. global tma
  64. global mediaImp
  65. global mediaList
  66. global mediaDir
  67. global theStream
  68. global ringMedia
  69. global hubMedia
  70. global hookMedia
  71. global backgroundMedia
  72. global textDisp  := undefined
  73. global tm        := undefined
  74.  
  75. class TapeMeasureAccessory (AccessoryContainer)
  76.    instance variables
  77.       accessoryAnswers:(new KeyedLinkedList)  --exported by AccessoryInterface module
  78. end
  79.  
  80. --*=============================================================================*
  81. --* Called by a Title (if necessary) to get a Tape Measure and the display
  82. --* portion which shows the readout.
  83. --*=============================================================================*
  84. method getAccessory self {class TapeMeasureAccessory} ->
  85.    (
  86.    return (#(tm, tm.display))
  87.    )
  88.  
  89. --*=============================================================================*
  90. --* Import all the necessary media and create the Tape Measure and its display
  91. --* readout.
  92. --*=============================================================================*
  93. mediaList := new KeyedLinkedList
  94.  
  95. mediaDir := spawn (parentDir theScriptDir) "media"
  96. theStream := getStream mediaDir "ring.bmp" @readable
  97. ringMedia := importMedia theImportExportEngine theStream \
  98.                                                @image    \
  99.                                                @dib      \
  100.                                                @bitmap
  101. plug theStream
  102. ringMedia.invisibleColor := whiteColor
  103.                                                  
  104. theStream := getStream mediaDir "crosshr.bmp" @readable
  105. hubMedia := importMedia theImportExportEngine theStream \
  106.                                               @image    \
  107.                                               @dib      \
  108.                                               @bitmap
  109. plug theStream
  110. hubMedia.invisibleColor := whiteColor
  111.  
  112. theStream := getStream mediaDir "tapeball.bmp" @readable
  113. hookMedia := importMedia theImportExportEngine theStream \
  114.                                                @image    \
  115.                                                @dib      \
  116.                                                @bitmap
  117. plug theStream
  118. hookMedia.matteColor := whiteColor
  119.  
  120. theStream := getStream mediaDir "tapedisp.bmp" @readable
  121. backgroundMedia := importMedia theImportExportEngine theStream \
  122.                                                      @image    \
  123.                                                      @dib      \
  124.                                                      @bitmap
  125. plug theStream
  126. backgroundMedia.matteColor := whiteColor
  127.  
  128. --*=============================================================================*
  129. --* Create TwoDShapes to hold the media and add them to the media list.
  130. --*=============================================================================*
  131. add mediaList @ring (new TwoDShape boundary:ringMedia)
  132. add mediaList @hub (new TwoDShape boundary:hubMedia)
  133. add mediaList @hook (new TwoDShape boundary:hookMedia)
  134. add mediaList @background (new TwoDShape boundary:backgroundMedia)
  135.  
  136. mediaList[@hub].position := new Point x:23 y:21  --Position the hub shape.
  137.  
  138. textDisp    := new TextDisplay media:mediaList
  139. tm          := new TapeMeasure media:mediaList display:textDisp
  140. tm.position := new Point x:40 y:50
  141.  
  142. --*=============================================================================*
  143. --* Create the tape measure accessory container and store the tape measure.
  144. --*=============================================================================*
  145. tma := new TapeMeasureAccessory dir:(parentDir theScriptDir) \
  146.                                 path:"tape.sxa"              \
  147.                                 mode:@create
  148. tma.name := "Tape Measure Object"
  149. tma.startupAction := 
  150.    (
  151.    tapeTMA ->
  152.       (
  153.       --*=======================================================================*
  154.       --* Load the interface and implementation modules.
  155.       --*=======================================================================*
  156.       forEach tapeTMA \
  157.          (
  158.          aModule xx -> 
  159.             (
  160.             load aModule
  161.             )
  162.          ) undefined
  163.       
  164.       --*=======================================================================*
  165.       --* Be a smart accessory and try to find a title to add yourself to.
  166.       --*=======================================================================*
  167.       for realTC in theOpenTitles do
  168.          (
  169.          if (isAppropriateAccessory realTC tapeTMA) do
  170.             (
  171.             --*=================================================================*
  172.             --* Unfortunately, isAppropriateAccessory defaults to returning 
  173.             --* 'true'.  So every Title will say "Sure!  Go ahead and add me!"
  174.             --* But I don't want that.  So I have to put an additional check in
  175.             --* here to make sure the title is using my accessory interface.
  176.             --* I think isAppropriateAccessory should default to returning 
  177.             --* 'false'.
  178.             --*=================================================================*
  179.             if (isDefined currentSceneGetter) and \
  180.                (canObjectDo realTC currentSceneGetter) do
  181.                (
  182.                tm.foundHome := false  --Make sure we can be added again.
  183.                tm.scale     := #(#("pixels", 1))  --Reset scale between scenes
  184.                addAccessory realTC tapeTMA
  185.                addToTitle tm realTC pres:realTC.currentScene
  186.                )
  187.             )
  188.          )
  189.       )
  190.    )
  191.  
  192. --*=============================================================================*
  193. --* Provide answers to the questions a title, e.g. AutoFinder, may want to know.
  194. --* These are just examples, AutoFinder only uses questions 1 and 2.
  195. --*=============================================================================*
  196. add tma.accessoryAnswers @question1 @yes --Do you want to add yourself to me?
  197. add tma.accessoryAnswers @question2 @yes --Do you inherit from TwoDPresenter?
  198. add tma.accessoryAnswers @question3 @yes --Can you be removed between scene changes?
  199. add tma.accessoryAnswers @question4 #()  --What is your cleanup method?
  200.  
  201. append tma (getModule @TapeMeasureInterface)
  202. append tma (getModule @TapeMeasureImplementation)
  203.  
  204. addUser (getStorageContainer (getModule @TapeInterface)) tma
  205.  
  206. close tma
  207.  
  208. "Compiled maketape.sx"
  209.  
  210. -->>>